package mt;


import java.util.*;

/**
 * @author zhangmin
 * @create 2022-03-18 20:20
 */
public class meituan2021_3_1 {

    public static void main(String[] args) {
        Scanner cin=new Scanner(System.in);
        int n=cin.nextInt();
        cin.nextLine();
        int[] w=new int[n];
        String[] strings = cin.nextLine().split(" ");
        for (int i = 0; i < n; i++) {
            w[i]=Integer.parseInt(strings[i]);
        }
        String[] s = cin.nextLine().split(" ");
        //用list来记录区间的划分情况
        List<int[]> list=new LinkedList<>();
        list.add(new int[]{0,n-1});
        for (int i = 0; i < n; i++) {
            int cur= Integer.parseInt(s[i])-1;
            //从cur处划分区间
            int curindex=0;
            for (int j = 0; j < list.size(); j++) {
                if(list.get(j)[0]<=cur&&list.get(j)[1]>=cur){
                    curindex=j;
                    break;
                }
            }
            int[] remove = list.remove(curindex);
            if (remove[0]<=cur-1){
                int[] left=new int[]{remove[0],cur-1};
                list.add(left);
            }
            if(remove[1]>=cur+1){
                int[] right=new int[]{cur+1,remove[1]};
                list.add(right);
            }
            int res=0;
            for (int j = 0; j < list.size(); j++) {
                int sum=0,start=list.get(j)[0],end=list.get(j)[1];
                for (int k = start; k <= end; k++) {
                    sum+=w[k];
                }
                res=Math.max(res,sum);
            }
            System.out.println(res);
        }
    }
}
